﻿using System;
using System.Drawing;
using System.Windows.Forms;


namespace BlueMarineWindowsFormsClient
{
    public class Status
    {
        private readonly ToolStripStatusLabel lblStatus;
        private readonly Timer _time = new Timer();
        private string message = "";
        private readonly int lgth;
        

        public Status(ToolStripStatusLabel stt)
        {
            lblStatus = stt;
            lblStatus.Click += lblStatus_Click;
            _time.Tick += timer_Tick;
            _time.Interval = 5000;
            lgth = stt.Width/7;
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            lblStatus.Text = "";
            _time.Stop();
        }

        private void lblStatus_Click(object sender, EventArgs e)
        {
            if (lblStatus.Text != "")
            {
                MessageBox.Show(message, "Status content", MessageBoxButtons.OK);
            }
        }

        private string reformatStt(string stt)
        {
            message = stt;
            if (stt.Length> lgth)
            {
                stt = stt.Replace("\n", " ").Substring(0, lgth) + "...";
            }
            return stt;
        }

        public void ERROR(string error)
        {
            lblStatus.ForeColor = Color.Red;
            lblStatus.Text = "ERROR: " + reformatStt(error);
           _time.Start();
        }

        public void SUCCESS(string success)
        {
            lblStatus.ForeColor = Color.SteelBlue;
            lblStatus.Text = "SUCCESS: " + reformatStt(success);
           _time.Start();
        }

        public void FAIL(string fail)
        {
            lblStatus.ForeColor = Color.OrangeRed;
            lblStatus.Text = "FAIL: " + reformatStt(fail);
           _time.Start();
        }

        public void STATUS(string status)
        {
            lblStatus.ForeColor = Color.Black;
            lblStatus.Text = reformatStt(status);
          _time.Start();
        }
    }
}